package cn.ffcs.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import cn.ffcs.db.DBConnection;

public class TestServlet extends HttpServlet
{

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException
    {
        DBConnection db=new DBConnection();

        PrintWriter out = null;
        response.setContentType("text/html; charset=GBK");
        response.setHeader("Cache-Control", "no-cache");
        response.setCharacterEncoding("GBK");
        
        String outStr = "var hdzx = [";
        
        String sUserID = (request.getParameter("userID_s")==null) ? "" : request.getParameter("userID_s");
        String misKey = (request.getParameter("misKey")==null) ? "": request.getParameter("misKey");
        sUserID = sUserID.toUpperCase();

//        outStr += "'有 $ 件运营互动中心待办。',0,''";
        String person=db.getUser(sUserID, misKey);
        int num = 0;
        String tmp = "";
        try
        {
            if (person != null && !"".equals(person))
            {
                num = db.getNum(person);
                outStr += "'有 $ 件产品运营互动中心待办。'," + num;
            }
            else
            {
                outStr += "'有 $ 件产品运营互动中心待办。',0";
            }
            outStr += ",'http://hdzx.fjtelecom.com/common/first.action?userID_s="
                    + sUserID + "&misKey=" + misKey + "&oaFlag=1'";
            outStr += "]";
            
            out = response.getWriter();
            tmp = new String(outStr.getBytes(), "GBK");
        }
        catch (UnsupportedEncodingException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        catch (IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        out.print(tmp);
        return;
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException
    {
        this.doGet(request, response);
    }
}
